package com.cskaoyan.shopping.controller.yingyuan;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.form.CheckAllItemRequest;
import com.cskaoyan.shopping.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 付常莹
 * @description: TODO
 * @date 2022/12/4 11:25
 * 该controller用于商品模块的删除购物车中的商品，全选或全不选三个接口
 */
@RestController
public class ShoppingController3 {

    @Autowired
    ICartService iCartService;

    /**
     * 该方法用于删除购物车中选中的商品
     * @param userId
     * @return
     * @author 付常莹
     */
    @DeleteMapping("shopping/items/{uid}")
    public ResponseData deleteChecked(@PathVariable("uid") Long userId){
        iCartService.deleteCheckedItem(userId);
        return new ResponseUtil<>().setData(null);
    }


    /**
     * 该方法用于删除购物车中的商品
     * @param uid
     * @param itemId
     * @return
     *  @author 付常莹
     */
    @DeleteMapping("shopping/carts/{uid}/{pid}")
    public ResponseData delete(@PathVariable("uid")  Long uid, @PathVariable("pid") Long itemId){
        iCartService.deleteCartItem(uid,itemId);
        return new ResponseUtil<>().setData(null);
    }



    /**
     * 该方法用于全选或全不选购物车中的商品的接口
     * @author 付常莹
     */
    @PutMapping("shopping/items")
    public ResponseData chooseAll(@Validated @RequestBody CheckAllItemRequest request){
        iCartService.checkAllCartItem(request);
        return new ResponseUtil<>().setData(null);
    }

}
